﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BrainTechLLC.Silverlight.Controls;

namespace BrainTechLLC.Silverlight.ClientApplication
{
    public partial class EditReset : BaseDataVisualizer, ISingleItemDataVisualizer
    {        
        public override void SetVisualizedData(DataVisualizer vis, object o) { Reset = o as Reset; base.SetVisualizedData(vis, o); }
        public Type VisualizeType { get { return typeof(Reset); } }
        public string VisualizerName { get { return "EditReset"; } }

        public static readonly DependencyProperty ResetProperty = DependencyProperty.Register(
            "Reset", typeof(Reset), typeof(EditReset), new PropertyMetadata(null, new PropertyChangedCallback(ResetChanged)));

        public Reset Reset
        {
            get { return (Reset)GetValue(ResetProperty); }
            set { SetValue(ResetProperty, value); }
        }

        public static void HandleChange<T2>(DependencyObject d, DependencyPropertyChangedEventArgs e, Action<EditReset, T2> action)
        {
            d.HandleChange<EditReset, T2>(e, action, (t) => t.UpdateBindings());
        }

        private static void ResetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            HandleChange<Reset>(d, e, (t, val) => t.Reset = val);
        }

        public override void UpdateBindings()
        {
            if (Reset != null)
            {
                gridData.DataContext = Reset;
            }
        }

        public override string TitleText
        {
            get
            {
                return (Reset == null) ? string.Empty :
                    string.Format("Reset {0} ({1})", Reset.Command, Reset.PopsAssociatedID);
            }
        }

        public EditReset()
        {
            InitializeComponent();
        }

        public override void OnSaveData()
        {
            DataAccess.Client.StoreResetAsync(DataAccess.AssignedUniqueId, Reset);
        }

        private void ShowProps_Loaded(object sender, RoutedEventArgs e)
        {
            //editResetProperties.Window.Indent = Window.Indent + 1;         
        }

        private void EditAssociatedIDCollection_RequestEditID(object sender, ObjectEventArgsNonRef<long> e)
        {
            OnRequestEditID(sender, e);
        }

        private void EditAssociatedIDCollection_RequestEditID1(object sender, ObjectEventArgsNonRef<long> e)
        {
            OnRequestEditID(sender, e);
        }

        private void EditAssociatedIDCollection_RequestEditID2(object sender, ObjectEventArgsNonRef<long> e)
        {
            OnRequestEditID(sender, e);
        }
    }
}